Start when sensor Sig Start is active
# Set train #12 at the station
If sensor SimMode is active
    Set block Sig Block 1 occupied
Endif
Assign short address 3 as #3 in Sig Block 1
Wait for 1 second

# Start moving
Set function key 0 on
Set function key 1 on, wait 1 seconds
Set direction to forward
Set speed to .5

If sensor SimMode is active
    Set block Sig Block 2 occupied
    Wait for 1 second
    Set block Sig Block 1 unoccupied
    Wait for 1 second
Endif

# Slow down and stop at a red signal head and wait for a green
If signal head SH-East-Bound does show Red
    Set speed to .4
    Set speed to .3
    Set speed to .2
    Set speed to .1
    Set speed to 0
    Wait for signal head SH-East-Bound to show Green
    Set speed to .5
Endif

If sensor SimMode is active
    Set block Sig Block 3 occupied
    Wait for 1 second
    Set block Sig Block 2 unoccupied
    Wait for 1 second
    Set block Sig Block 4 occupied
    Wait for 1 second
    Set block Sig Block 3 unoccupied
    Wait for 1 second
Endif

# Stop at a signal mast displaying Stop or Unlit (dark) and wait for a non stop aspect
If speed for signal mast SM-East-Bound is eq Stop
    Set speed to 0
    Wait for signal mast SM-East-Bound to not display Stop
    Set speed to .5
Endif

If sensor SimMode is active
    Set block Sig Block 5 occupied
    Wait for 1 second
    Set block Sig Block 4 unoccupied
    Wait for 1 second
    Set block Sig Block 6 occupied
    Wait for 1 second
    Set block Sig Block 5 unoccupied
    Wait for 1 second
Endif

# End of route, reverse direction
If block Sig Block 6 is occupied
    Set speed to 0
    Set direction to reverse
    Wait for 1 second
    Set speed to .5
Endif

If sensor SimMode is active
    Set block Sig Block 5 occupied
    Wait for 1 second
    Set block Sig Block 6 unoccupied
    Wait for 1 second
Endif

# If the mast displays stop, stop and wait for clear or approach
If signal mast SM-West-Bound does display Stop
    Set speed to .0
    Wait for signal mast SM-West-Bound to display Clear or Approach
    Set speed to .5
Endif

If sensor SimMode is active
    Set block Sig Block 4 occupied
    Wait for 1 second
    Set block Sig Block 5 unoccupied
    Wait for 1 second
Endif

# If the mast speed is less than normal wait for a clear speed (which is normal, also used by advanced approach)
If speed for signal mast SM-Speed is lt Normal
    Set speed to .0
    Wait while signal mast SM-Speed speed is less than Clear speed
    Set speed to .5
Endif

If sensor SimMode is active
    Set block Sig Block 3 occupied
    Wait for 1 second
    Set block Sig Block 4 unoccupied
    Wait for 1 second
Endif

# Check for head not Red
If signal head SH-West-Bound does show Red
    Set speed to .0
    Wait for signal head SH-West-Bound to not show Red
    Set speed to .5
Endif

If sensor SimMode is active
    Set block Sig Block 2 occupied
    Wait for 1 second
    Set block Sig Block 3 unoccupied
    Wait for 1 second
    Set block Sig Block 1 occupied
    Wait for 1 second
    Set block Sig Block 2 unoccupied
    Wait for 1 second
Endif

Wait for 1 seconds
Set speed to .0
Stop if sensor Sig Stop is active
